<?php
/*
 * Copyright (c) 2011 Todd Brady
 *
 * PS3Theatre is freely distributable under the terms of the MIT license.
 * For details, see the MIT-Licence web site: http://www.opensource.org/licenses/mit-license.php 
 */
	include_once("../includes/db_connect.php");
 
	$weatherQuery = "SELECT zip_code from tbl_weather";
	$weatherResult=mysql_query($weatherQuery);
	$weatherRow = mysql_fetch_array($weatherResult);
	
	$zipCode = 	$weatherRow['zip_code'];
	
	//forcast api for weather underground
	$xml = @simplexml_load_file('http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query='.$zipCode);
	if($xml != false){
		$simpleforecast = $xml->xpath("/forecast/simpleforecast");
		$days = array();
		
		$i = 0;
	
		while($i < 5 && $i < count($simpleforecast[0]->forecastday)){
			$days[$i]['title'] = $simpleforecast[0]->forecastday[$i]->date[0]->weekday;
			$days[$i]['icon'] = $simpleforecast[0]->forecastday[$i]->icon;
			$days[$i]['high'] = $simpleforecast[0]->forecastday[$i]->high[0]->fahrenheit;
			$days[$i]['low'] = $simpleforecast[0]->forecastday[$i]->low[0]->fahrenheit;
			$days[$i]['desc'] = $simpleforecast[0]->forecastday[$i]->conditions;
			
			$i++;
		}
		
		echo '<table cellspacing="25">
				<tr>';
				
		$i = 0;
		while($i < count($days)){
			echo '<td>';
			echo '<table width="294" height="431" cellpadding="0" cellspacing="0" style="background:url(images/home_weather_small.png); text-align:center;">
					<tr height="98">';
			echo '<td colspan="2" class="dayCell">'.strtoupper($days[$i]['title']).'</td>
				</tr>
				<tr height="139">
					<td class="highCell">';
			echo $days[$i]['high'];
//			echo '&deg; F';
			echo '</td>
			<td class="lowCell">';
			echo $days[$i]['low'];
//			echo '&deg; F';
			echo '</td>
			</tr>';
			echo '<tr height="194">
					<td colspan="2" class="weatherDescCell">'.'<img src="/images/weather/weather_icons/'.$days[$i]['icon'].'.png" height="128" width="128"/>
					<br/>'.$days[$i]['desc'];
			echo '</td>
</tr>
</table>';						
			echo '</td>';	
			$i++;
		}
			
		echo '</tr>
				</table>';
		}
?>